package org.icosagon.core.math;

import java.util.Hashtable;
import java.util.Map;
import java.util.Vector;
import org.icosagon.core.Modifiable;

/**
 * This will allow you to tie <code>Modifiable</code> objects to
 * a variable name so that the <code>Equation</code> objects
 * will have a value to assign to any variables.<br />
 * <br />
 * This class is constucted as a singleton object so that all of the
 * variables assigned can be reached throughout the application
 * and so that they are always consistant.<br />
 * @author Daniel Owens
 */
public class VariableMap {
    private Hashtable<String,String> map = new Hashtable<String,String>();
    
    private VariableMap() {}

    public void putVariable(String name, Modifiable value) {
        this.map.put(name, value.getName());
    }

    public void putAll(Map<String,String> vars) {
        this.map.putAll(vars);
    }

    public void removeVariable(String name) {
        this.map.remove(name);
    }

    public String getVariable(String name) {
        return this.map.get(name);
    }

    public Vector<String> getVariables() {
        return (Vector<String>) map.keys();
    }

   public static VariableMap getVariableMap() {
     return MapHolder.INSTANCE;
   }

   private static class MapHolder {
     private static final VariableMap INSTANCE = new VariableMap();
   }
}
